package cn.bkw.ytkapi.services.impl;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.bkw.ytkapi.utils.HttpClientUtils;
import org.springframework.stereotype.Service;

import cn.bkw.ytkapi.services.UserInfoServices;
import cn.bkw.ytkapi.utils.HttpClientUtil;


@Service("userInfoServices")
public class UserInfoServiceimpl extends HttpClientUtil implements UserInfoServices{

	//登录
	@Override
	public String login(HttpServletRequest request,String username,String password) {
		String result = "";
		String url="/login";
		try {
			Map<String, String> map = new HashMap<String, String>();
			map.put("username", username);
			map.put("password", password);
			long start = System.currentTimeMillis();
			result = sendHttpPost(url, map);
			long end = System.currentTimeMillis();
			if(result.equals("") || "".equals(result)) {
				return "{\"errcode\":\"4002\",\"msg\": \" "+ url +" \" 接口返回为空,查询时间 :" + (end - start) / 1000f + "秒\"}";
			}
			return result;

		}catch (Exception e){
			result = "{\"errcode\":\"5000\",\"msg\": \" "+ url +" \" 接口出现错误：" + e + "\"}";
		}
		return result;
	}

	@Override
	public String commonRequest(String url, Map<String, String> map, HttpServletRequest req) throws Exception {
		String result = "";
		try {
			Map<String, String> map1 = new HashMap<String, String>();
			map1.putAll(map);
			long start = System.currentTimeMillis();
			result = sendHttpPost2(url, map1);
			long end = System.currentTimeMillis();
			if(result.equals("") || "".equals(result)) {
				return "{\"status\":\"4002\",\"msg\": \" "+ url +" \" 接口返回为空,查询时间 :" + (end - start) / 1000f + "秒\"}";
			}
			return result;

		}catch (Exception e) {
			result = "{\"status\":\"5000\",\"msg\": \" "+ url +" \" 接口出现错误：" + e + "\"}";
		}

		return result;
	}


}

